#include "../include/ini.h"
#include "../include/create.h"
#include "../include/hanzi.h"
void disvisable_menu(menu *head){
menu *p=head->next;
head->expand=0;
while(p){
p->load(p);
p=p->next;
}
}

int expand(void *p,menu *m){
menu *head=(menu *)p;
head->expand ^=1;
if(head->expand==1){
while(head){
head->save(head);
head->print_caption(head);
head=head->next;
}
}else{
while(head){
if(head->isroot==0)
head->load(head);
head=head->next;
}
}
return 1;
}
int _reboot(void *p,menu *m){
disvisable_menu(m);
system("clear >>//dev//tty0");
system("echo Your computer will reboot now >>//dev//tty0");
system("reboot");
return 1;
}
int __exit(void *p,menu *m){
disvisable_menu(m);
int ret;
int i,j,k=0;
#ifdef COLOR32
extern unsigned long *buf_fb;
#else
extern unsigned short *buf_fb;
#endif

for(i=0;i<H_272;i++)
for(j=0;j<W_480;j++)
buf_fb[i*W_480+j]=0;
_exit(0);
return 1;
}
int _poweroff(void *p,menu *m){
disvisable_menu(m);
system("poweroff");
return 1;
}
int _console(void *p,menu *m){
//__exit(p);
//break;
disvisable_menu(m);
system("console");
__exit(p,m);
return 1;
}
int _gongju(void *p,menu *m){
disvisable_menu(m);
return 1;
}
int nothing(void *p,menu *m){
disvisable_menu(m);
//----------------------------
widget *w=malloc(sizeof(widget));
init_widget(w);
w->set_pos(w,0,0,W_480,(H_272-50));
w->save(w);
w->settitle(w,"Home");
w->setcmd(w,"/home");
w->show(w);
redraw_task_bar();
//---------------------------
return 1;
}
int flash(void *p,menu *head){//it is not useful
disvisable_menu(head);
menu *m=head;
widget *w=(widget *)m->data;
if(w->visible==0){
w->show(w);
w->visible=1;
}else {
w->hide(w);
w->visible=0;
} 
return 1;
}
menu * create_menu1(){
menu *head,*p1,*p2;
head=malloc(sizeof(menu));
init_menu(head);
head->init(head,MENU_LEFT,H_272-MENU_H,1,0);//
head->setexpand(head,0);//
head->settitle(head,"Start",7);
//head->addcaption(head,ying);
//head->addcaption(head,yong);
//head->addcaption(head,cheng);
//head->addcaption(head,xu);
head->function=expand;
head->save(head);//
//-------------------------
p1=head;
//-----------------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,MENU_LEFT,H_272-MENU_H*2,0,0);//
p2->setexpand(p2,0);//
p2->settitle(p2,"Exit",4);
//p2->addcaption(p2,tui);
//p2->addcaption(p2,chu);
p2->function=__exit;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;
//---------------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,MENU_LEFT,H_272-MENU_H*2-2,0,0);//
p2->type=SEPARATOR_TYPE;//
p2->function=nothing;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;
//----------------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,MENU_LEFT,H_272-MENU_H*3-2,0,0);//
p2->setexpand(p2,0);//
p2->settitle(p2,"Shut",4);
//p2->addcaption(p2,guan);
//p2->addcaption(p2,ji);
p2->function=_poweroff;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;
//--------------------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,MENU_LEFT,H_272-MENU_H*4-2,0,0);//
p2->setexpand(p2,0);//
p2->settitle(p2,"Reboot",6);
//p2->addcaption(p2,chong);
//p2->addcaption(p2,qi);
p2->function=_reboot;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;
//-------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,MENU_LEFT,H_272-MENU_H*5-2,0,0);//
p2->setexpand(p2,0);//
p2->settitle(p2,"Tools",5);
//p2->addcaption(p2,gong);
//p2->addcaption(p2,ju);
p2->function=nothing;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;
//-------------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,MENU_LEFT,H_272-MENU_H*6-2,0,0);
p2->setexpand(p2,0);
p2->settitle(p2,"Console",7);
//p2->addcaption(p2,zhong);
//p2->addcaption(p2,duan);
p2->function=_console;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;

return head;
}
menu * create_menu2(){
menu *head,*p1,*p2;
head=malloc(sizeof(menu));
init_menu(head);
head->init(head,MENU_LEFT+MENU_W,H_272-MENU_H,1,0);//
head->setexpand(head,0);//
head->settitle(head,"Place",5);
//head->addcaption(head,wei);
//head->addcaption(head,zhi);
head->function=expand;
head->save(head);//
//-------------------------
p1=head;
//-----------------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,MENU_LEFT+MENU_W,H_272-MENU_H*2,0,0);//
p2->setexpand(p2,0);//
p2->settitle(p2,"home",7);
//p2->addcaption(p2,zhuo);
//p2->addcaption(p2,mian);
p2->function=nothing;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;/*
//---------------------
p2=malloc(sizeof(menu));
init_menu(p2);
p2->init(p2,132,221,0,0);//
p2->type=SEPARATOR_TYPE;//
p2->function=nothing;
p2->save(p2);
p2->pre=p1;
p2->next=NULL;
p1->next=p2;
p1=p2;*/

return head;
}
void create_task_bar(menu *m){
init_menu(m);
//m->init(m,232,247,2,0);
m->init(m,MENU_LEFT+MENU_W*2,H_272-25,2,0);
m->next=NULL;
m->data=NULL;
}
